<template>
  <div class="z-dialog__warpper" v-show="visible" @click.self="cloceDialog">
    <transition name="dialog-">
        <div class="z-dialog" :style="{width, marginTop:top}">
      <div class="z-dialog__header">
        <div class="z-dialog__title">
          <slot name="title"><span>{{title}}</span></slot>
          </div>
        <button class="z-dialog__headerbtn" @click="cloceDialog">
          <i class="z-icon-pic"></i>
        </button>
      </div>
      <div class="z-dialog__body">
        <slot name="body"></slot>
      </div>
      <div class="z-dialog__footer" v-if="this.$slots.footer">
        <slot name="footer"></slot>
      </div>
    </div>
    </transition>

  </div>
</template>

<script>
export default {
  name: 'ZDialog',
  props: {
    width: {
      type: String,
      default: '400px'
    },
    top: {
      type: String,
      default: '15vh'
    },
    title: {
      type: String,
      default: '提示'
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    cloceDialog () {
      this.$emit('update:visible', false)
    }
  }
}
</script>

<style lang="scss" scoped>
.z-dialog__warpper {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  background: rgba(0, 0, 0, 0.5);
  .z-dialog {
    display: inline-block;
    width: 420px;
    padding: 10px;
    vertical-align: middle;
    background-color: #fff;
    border-radius: 4px;
    border: 1px solid #ebeef5;
    font-size: 18px;
    -webkit-box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    text-align: left;
    overflow: hidden;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    &__header {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    &__footer {
      display: flex;
      justify-content: flex-end;
    }
  }
}
</style>
